/*
 * @Author: tianchunyu
 * @Date: 2020-05-11 18:01:11
 * @LastEditTime: 2020-06-01 16:58:49
 * @LastEditors: Please set LastEditors
 * @Description: lifter mechanical structure drive
 * @FilePath: \X\app\xp\driver\lifter_s.c
 */
#include "lifter_s.h"
LIFTER_class lifter={0};
static u8 ifstopflag = 0;
/**
 * @description: xp_lifter_config The configuration of the lifter motor hander 
 * @param {type} void 
 * @return: 
 */
void xp_lifter_config(void)
{

    synro_lifter_handler_A.config.drivemode = syn_pos_abs_speed;
    synro_lifter_handler_B.config.drivemode = syn_pos_abs_speed;    
    lifter.motor[0] = &synro_lifter_handler_A;
    lifter.motor[1] = &synro_lifter_handler_B;
    lifter.encode_A_motor0 = 0;     //
    lifter.encode_B_motor1 = 0;
    lifter.coord_A_Y = 0;
    lifter.coord_B_Y = 0;
    lifter.coord_Y = 0;
    lifter.init =0;
        
}
/**
 * @description: xp_lifter_init 
 * @param {type}  port:modbus uart port
                  speed:modbus uart speed
 * @return: 
 *          0 success
 *          -1 fail
 */

int xp_lifter_init(u8 port,int speed)
{
    int ret = 0;
    if(lifter.init == 1)
    {
        LOG_SYNRON("xp_lifter_init initialized ！！！ ");
        return 0;
    }
    xp_lifter_config();
    /*debug 临时地址    后续改成     */
    ret = synron_hander_init(&synro_lifter_handler_A,1,SYNRON_A_MOTOR_LIFTER_SLAVEID,port,speed);
    if(ret != 0)
    {
        LOG_SYNRON("synron_hander_init synro_lifter_handler_A fail !");
        return -1;
    }
    ret = synron_hander_init(&synro_lifter_handler_B,2,SYNRON_B_MOTOR_LIFTER_SLAVEID,port,speed);
    if(ret != 0)
    {
        LOG_SYNRON("synron_hander_init synro_lifter_handler_B fail !");
        return -1;
    }
    /* absolute position mode 4*/
    ret = xp_synron_position_init(&synro_lifter_handler_A,syn_pos_abs_speed);
    if(ret != 0)
    {
        LOG_SYNRON("xp_synron_position_init synro_lifter_handler_A fail !");
        return -1;
    }
    ret = xp_synron_position_init(&synro_lifter_handler_B,syn_pos_abs_speed);
    if(ret != 0)
    {
        LOG_SYNRON("xp_synron_position_init synro_lifter_handler_A fail !");
        return -1;
    }
    synron_set_default_rotation(&synro_lifter_handler_A,0);
    synron_set_default_rotation(&synro_lifter_handler_B,0);
    /*
    
    */
    ret = synron_write_register(&synro_lifter_handler_A,PARAMETER_POS_BIAS_SETVALUE,0);
    if(ret != SYNRON_SUCCESS)
    {
        LOG_SYNRON("synron_write_register  synro_lifter_handler_A PARAMETER_POS_BIAS_SETVALUE fail !");
        return SYNRON_COMMUN_ERR;
    }
    ret = synron_write_register(&synro_lifter_handler_B,PARAMETER_POS_BIAS_SETVALUE,0);
    if(ret != SYNRON_SUCCESS)
    {
        LOG_SYNRON("synron_write_register  synro_lifter_handler_B PARAMETER_POS_BIAS_SETVALUE fail !");
        return SYNRON_COMMUN_ERR;
    }
    
    ret = synron_write_register(&synro_lifter_handler_A,PARAMETER_POS_BIAS_SETVALUE,0);
    if(ret != SYNRON_SUCCESS)
    {
        LOG_SYNRON("synron_write_register  synro_lifter_handler_A PARAMETER_POS_BIAS_SETVALUE fail !");
        return SYNRON_COMMUN_ERR;
    }
    ret = synron_write_register(&synro_lifter_handler_B,PARAMETER_POS_BIAS_SETVALUE,0);
    if(ret != SYNRON_SUCCESS)
    {
        LOG_SYNRON("synron_write_register  synro_lifter_handler_B PARAMETER_POS_BIAS_SETVALUE fail !");
        return SYNRON_COMMUN_ERR;
    }


    
    /* Zero position is calibrated for each initialization and board and drive restart*/
    ret = synron_position_re_encode_setvalue(&synro_lifter_handler_A,0);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_A fail !");
        return -1;
    }
    ret = synron_position_re_locacmd_setvalue(&synro_lifter_handler_A,0);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_A fail !");
        return -1;
    }
    ret = synron_position_re_encode_setvalue(&synro_lifter_handler_B,0);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
        return -1;
    }    
    ret = synron_position_re_locacmd_setvalue(&synro_lifter_handler_B,0);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
        return -1;
    }

    
        //电缸输入输出信号的配置急停信号的配置以及输出故障的配置
    
    ret = synron_write_register(&synro_lifter_handler_A,PARAMETER_STOP_EMG,-1);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
        return -1;
    }
    ret = synron_write_register(&synro_lifter_handler_B,PARAMETER_STOP_EMG,-1);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
        return -1;
    }
    ret = synron_write_register(&synro_lifter_handler_A,PARAMETER_OUPUT_1_SET,-5);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
        return -1;
    }
    ret = synron_write_register(&synro_lifter_handler_B,PARAMETER_OUPUT_1_SET,-5);
    if(ret != 0)
    {
        LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
        return -1;
    }
    
    /*
        电缸加减速时间设置
    */
    ret = xp_lifter_accdcctime_set(&lifter, 300);
    if(ret != 0)
    {
        LOG_SYNRON("xp_lifter_accdcctime_set fail !");
        return -1;
    }
    
    ret = synron_speedmode_acceleratetime(&synro_lifter_handler_A,2);
    if(ret != 0)
    {
        LOG_SYNRON("synron_speedmode_acceleratetime synro_lifter_handler_A fail !");
        return -1;
    }
    ret = synron_speedmode_acceleratetime(&synro_lifter_handler_B,2);
    if(ret != 0)
    {
        LOG_SYNRON("synron_speedmode_acceleratetime synro_lifter_handler_B fail !");
        return -1;
    }
    ret = synron_speedmode_deceleratetime(&synro_lifter_handler_A,2);
    if(ret != 0)
    {
        LOG_SYNRON("synron_speedmode_deceleratetime synro_lifter_handler_A fail !");
        return -1;
    }
    ret = synron_speedmode_deceleratetime(&synro_lifter_handler_B,2);
    if(ret != 0)
    {
        LOG_SYNRON("synron_speedmode_deceleratetime synro_lifter_handler_A fail !");
        return -1;
    }
    
    
    /*
        急停信号反逻辑，初始化要上电使得继电器导通，继电器输出端不导通急停信号有效
    */
    xp_io_output_set(1, L_INPUT_PIN_A,L_LOW_STATE);
    xp_io_output_set(1, L_INPUT_PIN_B,L_LOW_STATE);
    aos_msleep(500);
    /*wait*/
    
    
    ret = synron_read_hold(&synro_lifter_handler_A,STATE_DIGITAL_PHYSICAL_INPUT);
    if(ret != 1)
    {
        LOG_SYNRON("synro_lifter_handler_A STATE_DIGITAL_PHYSICAL_INPUT error");
        return -1;
    }
    ret = synron_read_hold(&synro_lifter_handler_B,STATE_DIGITAL_PHYSICAL_INPUT);
    if(ret != 1)
    {
        LOG_SYNRON("synro_lifter_handler_B STATE_DIGITAL_PHYSICAL_INPUT error");
        return -1;
    }
    
    
    lifter.init = 1;
    aos_msleep(500);
    ret = xp_lifter_check_zero();
    if(ret != 0)
    {
        LOG_SYNRON("xp_lifter_check_zero error");
        return -1;
    }
    LOG_SYNRON("lifter module init success~");
    return 0;
}
/**
 * @description:  xp_lifter_move 
 * @param {type}  lifter:lifter hander
                  coordinate_y:a specified absolute locate axis     unit mm
                  time_ms: Time taken to move to a specified location  unit ms
 * @return: 
 *          0 success
 *          -1 fail
 */

int xp_lifter_move_t(LIFTER_class*lifterp,double coordinate_y,u16 time_ms)
{
    int ret1 = 0;
    int ret2 = 0;
    int ret3 = 0;
    s32 pulse_value = 0;
    if(coordinate_y <0 || time_ms<0)
    {
        LOG_SYNRON("coordinate_y error and time_ms error");
        return SYNRON_COMMUN_ERR;
    }
    pulse_value = (s32)(COR_DISY_TO_COR_PULS * coordinate_y);
    ret1 = xp_lifter_get_locate(lifterp);
    if(ret1 != SYNRON_SUCCESS)
    {
        LOG_SYNRON("xp_lifter_get_locate fail ");
        return SYNRON_COMMUN_ERR;
    }
    ret1 = synron_position_setvalue(lifterp->motor[0],pulse_value,time_ms);//A motor
    if(ret1 !=SYNRON_SUCCESS)
    {
        LOG_SYNRON("synron_position_setvalue motor A error ! ");
        return SYNRON_COMMUN_ERR;
    }
    ret2 = synron_position_setvalue(lifterp->motor[1],pulse_value,time_ms);//B motor
    if(ret2 !=SYNRON_SUCCESS)
    {
        LOG_SYNRON("synron_position_setvalue motor B error ! ");
        ret3 = synron_position_setvalue(lifterp->motor[0],0,0);
        if(ret3 != SYNRON_SUCCESS)
        {
            /*
              Some urgent measures need to be taken here for motorA   
            */  
            LOG_SYNRON("xp_lifter_stop motorA  fail  and it may be a accident");   
            
        }
        return SYNRON_COMMUN_ERR;
    }
    return SYNRON_SUCCESS;
}
/**!!!
 * @description:  xp_lifter_move_s 
 * @param {type}  lifter:lifter hander
                  coordinate_y:a specified absolute locate axis
                  runspeed:  move to a specified location by specific speed unit m/s  no positive or negative
 * @return: 
 *          0 success
 *          -1 fail
 */
int xp_lifter_move_s(LIFTER_class*lifterp,double coordinate_y,double runspeed)
{
    int ret1 = 0;
    int ret2 = 0;
    int ret3 = 0;
    s32 pulse_value1 = 0;
    double coordin_last = 0;
    u16 time_ms = 0;
    u16 moter_speed = 0;        //电机转数 prm 每分钟
    static s32 left_encode = 1;
    static s32 right_encode = 1;
    s16 speedl = 0;
    s16 speedr = 0;
    if(lifterp->init != 1)
    {
        LOG_SYNRON("lifterp->init != 1");
        return -1;
    }
    if(coordinate_y <0 || runspeed<0)
    {
        LOG_SYNRON("coordinate_y error and runspeed error");
        return -1;
    }
    if(runspeed > 0.15)
    {
        LOG_SYNRON("runspeed > 0.15");
        return -1;
    }
    if(coordinate_y>SAFE_HEIGHT)   
    {
        LOG_SYNRON("coordinate_y>SAFE_HEIGHT");
        return -1;
    }
    pulse_value1 = (s32)(COR_DISY_TO_COR_PULS * coordinate_y);
    ret1 = xp_lifter_get_locate(lifterp);
    if(ret1 != 0)
    {
        LOG_SYNRON("xp_lifter_get_locate fail ");
        return -1;
    }
    LOG_SYNRON("left_encode:%d right_encode:%d",left_encode,right_encode);
    if(lifterp->coord_Y<-5)
    {
        /*
            临时报警动作
            
        */
       xp_lifter_error_anction();
       LOG_SYNRON("lifterp->coord_Y<-5");
       return -1;
    }
    moter_speed = (u16)(runspeed *COR_UPDOWNSPEED_TO_MPTORPRM);
    LOG_SYNRON("====>endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s moter_speed %d prm",coordinate_y,lifterp->coord_Y,fabs(lifterp->coord_Y -coordinate_y),runspeed,moter_speed);
    ret1 = synron_position_setvalue(lifterp->motor[0],pulse_value1,moter_speed);//A motor
    if(ret1 !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
    ret2 = synron_position_setvalue(lifterp->motor[1],pulse_value1,moter_speed);//B motor
    
    if(ret2 !=0)
    {
        LOG_SYNRON("====>synron_position_setvalue motor B error ! ");
        ret3 = synron_position_setvalue(lifterp->motor[0],0,0);
        if(ret3 != 0)
        {
            /*
              Some urgent measures need to be taken here for motorA   
            */ 
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            LOG_SYNRON("xp_lifter_stop motorA  fail  and it may be a accident");               
        }
        return -1;
    }
    ifstopflag = 0;
    while(1)
    {   
        
        ret1 = xp_lifter_get_locate(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
             xp_lifter_error_anction();
            return -1;
        }
        if(ifstopflag == 1)
        {
            break;
        }
        //LOG_SYNRON("left_encode:%d encode_A_motor0_Y:%d right_enccode:%d encode_B_motor1:%d",left_encode,lifterp->encode_A_motor0,right_encode,lifterp->encode_B_motor1);
        if(((left_encode == lifterp->encode_A_motor0 )&&(fabs(lifterp->encode_A_motor0 -pulse_value1)>200))||
            ((right_encode == lifterp->encode_B_motor1)&&(fabs(lifterp->encode_B_motor1-pulse_value1)>200)))
        {
            LOG_SYNRON("\r\n ERROR \r cummunication error xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作            
            */
             LOG_SYNRON("\r\n left_encode %d right_encode %d  encode_A_motor0 %d encode_B_motor1 %d pulse_value1 %d ",left_encode,right_encode,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value1);
             xp_lifter_error_anction();
            return -1;
        }
        if(fabs(lifterp->coord_A_Y-lifterp->coord_B_Y)>3)/*如果左边和右边相差过大*/
        {
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            LOG_SYNRON("\r\n ERROR \r The height difference between the left cylinder and the right cylinder is too great ");
            LOG_SYNRON("\r\n coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d",lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1);
            return -1;
        }
        LOG_SYNRON("\r\n diff_s %f coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d pulse_value1 %d",fabs(lifterp->coord_A_Y-lifterp->coord_B_Y),lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value1);
        /*
        speedl = synron_get_speedvalue(lifterp->motor[0]);
        speedr = synron_get_speedvalue(lifterp->motor[1]);
        LOG_SYNRON("lifterp->motor[0]  %d lifterp->motor[1]  %d",speedl,speedr);
        */
        if((fabs(left_encode-pulse_value1)<40)&&(fabs(right_encode -pulse_value1)<40))
        {
            LOG_SYNRON("The target coordinates reach the specified position");
            ifstopflag = 0;
            break ;
        }
         ret1 = xp_lifter_read_inputsig();
        if(ret1 == -1)
        {
            LOG_SYNRON("xp_lifter_read_inputsig ret %d",ret1);
            break;
        }
        left_encode = lifterp->encode_A_motor0;
        right_encode = lifterp->encode_B_motor1;
        aos_msleep(200);
    }
    return 0;
    
}


/**!!!
 * @description:  xp_lifter_move_s 
 * @param {type}  lifter:lifter hander
                  coordinate_y:a specified absolute locate axis
                  runspeed:  move to a specified location by specific speed unit m/s  no positive or negative
 * @return: 
 *          0 success
 *          -1 fail
 */
int xp_lifter_move_s_a(LIFTER_class*lifterp,double coordinate_y,double runspeed)
{
    int ret1 = 0;
    int ret2 = 0;
    int ret3 = 0;
    s32 pulse_value1 = 0;
    double coordin_last = 0;
    u16 time_ms = 0;
    u16 moter_speed = 0;
    static s32 left_encode = 0;
    s16 speedl = 0;
    if(runspeed<0)
    {
        LOG_SYNRON("coordinate_y error and runspeed error");
        return -1;
    }
    if(runspeed > 0.15)
    {
        LOG_SYNRON("runspeed > 0.15");
        return -1;
    }
    if(coordinate_y>SAFE_HEIGHT)   
    {
        LOG_SYNRON("coordinate_y>SAFE_HEIGHT");
        return -1;
    }
    pulse_value1 = (s32)(COR_DISY_TO_COR_PULS * coordinate_y);
    ret1 = xp_lifter_get_locate_a(lifterp);
    if(ret1 != 0)
    {
        LOG_SYNRON("xp_lifter_get_locate fail ");
        return -1;
    }
    left_encode = lifterp->encode_A_motor0;
    LOG_SYNRON("left_encode:%d",left_encode);
    //time_ms = (u16)((1000.0)*(fabs(lifterp->coord_A_Y -coordinate_y))/(runspeed*1000.00));  //算出运动到指定位置的时间 ms
    //LOG_SYNRON("==pulse_value1 %d endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s time_ms %dms",pulse_value1,coordinate_y,lifterp->coord_A_Y,fabs(lifterp->coord_A_Y -coordinate_y),runspeed,time_ms);
    moter_speed = (u16)(runspeed *COR_UPDOWNSPEED_TO_MPTORPRM);
    LOG_SYNRON("==pulse_value1 %d endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s moter_speed %d prm",pulse_value1,coordinate_y,lifterp->coord_A_Y,fabs(lifterp->coord_A_Y -coordinate_y),runspeed,moter_speed);
    ret1 = synron_position_setvalue(lifterp->motor[0],pulse_value1,moter_speed);//A motor
    if(ret1 !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
    aos_msleep(500);
    /*运行过程不断读数据确保同步*/
    while(1)
    {   
        ret1 = xp_lifter_get_locate_a(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            return -1;
        }
        //LOG_SYNRON("left_encode:%d encode_A_motor0_Y:%d right_enccode:%d encode_B_motor1:%d",left_encode,lifterp->encode_A_motor0,right_encode,lifterp->encode_B_motor1);
        LOG_SYNRON("\r\n coord_A_Y:%f  encode_A_motor0 %d  ",lifterp->coord_A_Y,lifterp->encode_A_motor0);
        if(abs(left_encode-pulse_value1)<40)
        {
            LOG_SYNRON("The target coordinates reach the specified position");
            break;
        }
        /*
        ret1 = xp_lifter_read_inputsig();
        if(ret1 == 0)
        {
            break;
        }
        */
        left_encode = lifterp->encode_A_motor0;
        aos_msleep(200);
    }
    return 0;
    
}




/**!!!
 * @description:  xp_lifter_move_s 
 * @param {type}  lifter:lifter hander
                  coordinate_y:a specified absolute locate axis
                  runspeed:  move to a specified location by specific speed unit m/s  no positive or negative
 * @return: 
 *          0 success
 *          -1 fail
 */
int xp_lifter_move_s_b(LIFTER_class*lifterp,double coordinate_y,double runspeed)
{
    int ret1 = 0;
    int ret2 = 0;
    int ret3 = 0;
    s32 pulse_value1 = 0;
    double coordin_last = 0;
    u16 time_ms = 0;
    u16 moter_speed = 0;
    static s32 right_encode = 0;
    s16 speedr = 0;
    if(runspeed<0)
    {
        LOG_SYNRON("coordinate_y error and runspeed error");
        return -1;
    }
    if(runspeed > 0.15)
    {
        LOG_SYNRON("runspeed > 0.15");
        return -1;
    }
    if(coordinate_y>SAFE_HEIGHT)   
    {
        LOG_SYNRON("coordinate_y>SAFE_HEIGHT");
        return -1;
    }
    pulse_value1 = (s32)(COR_DISY_TO_COR_PULS * coordinate_y);
    ret1 = xp_lifter_get_locate_b(lifterp);
    if(ret1 != 0)
    {
        LOG_SYNRON("xp_lifter_get_locate fail ");
        return -1;
    }
    right_encode = lifterp->encode_B_motor1;
    LOG_SYNRON("left_encode:%d",right_encode);
    //time_ms = (u16)((1000.0)*(fabs(lifterp->coord_B_Y -coordinate_y))/(runspeed*1000.00));  //算出运动到指定位置的时间 ms
    //LOG_SYNRON("==pulse_value1 %d endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s time_ms %dms",pulse_value1,coordinate_y,lifterp->coord_A_Y,fabs(lifterp->coord_A_Y -coordinate_y),runspeed,time_ms);
    moter_speed = (u16)(runspeed *COR_UPDOWNSPEED_TO_MPTORPRM);
    LOG_SYNRON("==pulse_value1 %d endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s moter_speed %d prm",pulse_value1,coordinate_y,lifterp->coord_A_Y,fabs(lifterp->coord_A_Y -coordinate_y),runspeed,moter_speed);
    ret1 = synron_position_setvalue(lifterp->motor[1],pulse_value1,moter_speed);//B motor
    if(ret1 !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
    aos_msleep(500);
    /*运行过程不断读数据确保同步*/
    while(1)
    {   
        ret1 = xp_lifter_get_locate_b(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
           xp_lifter_error_anction();
            return -1;
        }
        //LOG_SYNRON("left_encode:%d encode_A_motor0_Y:%d right_enccode:%d encode_B_motor1:%d",left_encode,lifterp->encode_A_motor0,right_encode,lifterp->encode_B_motor1);
        LOG_SYNRON("\r\n coord_B_Y:%f  encode_B_motor1 %d  ",lifterp->coord_B_Y,lifterp->encode_B_motor1);
        if((fabs(right_encode-pulse_value1)<40))
        {
            LOG_SYNRON("The target coordinates reach the specified position");
            break ;
        }
        ret1 = xp_lifter_read_inputsig();
        if(ret1 == 0)
        {
            break;
        }
        right_encode = lifterp->encode_B_motor1;
        aos_msleep(200);
    }
    return 0;
    
}



/**
 * @description:  xp_lifter_move_s 
 * @param {type}  lifter:lifter hander
                  coordinate_y:a specified absolute locate axis
                  runspeed:  move to a specified location by specific speed unit m/s  no positive or negative
 * @return: 
 *          0 success
 *          -1 fail
 */



int xp_lifter_move_abs(LIFTER_class*lifterp,double coordinate_y,double runspeed)
{
    int ret1 = 0;
    int ret2 = 0;
    int ret3 = 0;
    s32 pulse_value1 = 0;
    double coordin_last = 0;
    u16 time_ms = 0;
    u16 moter_speed = 0;        //电机转数 prm 每分钟
    static s32 left_encode = 0;
    static s32 right_encode = 0;
    if(lifterp->init != 1)
    {
    LOG_SYNRON("lifterp->init != 1");
    return -1;
    }
    if(runspeed<0)
    {
        LOG_SYNRON("coordinate_y error and runspeed error");
        return -1;
    }
    pulse_value1 = (s32)(COR_DISY_TO_COR_PULS * coordinate_y);
    ret1 = xp_lifter_get_locate(lifterp);
    if(ret1 != 0)
    {
        LOG_SYNRON("xp_lifter_get_locate fail ");
        return -1;
    }
    //time_ms = (u16)((1000.0)*(fabs(lifterp->coord_Y -coordinate_y))/(runspeed*1000.00));  //算出运动到指定位置的时间 ms
    //LOG_SYNRON("====>endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s time_ms %dms",coordinate_y,lifterp->coord_Y,fabs(lifterp->coord_Y -coordinate_y),runspeed,time_ms);
    moter_speed = (u16)(runspeed *COR_UPDOWNSPEED_TO_MPTORPRM);
    LOG_SYNRON("====>endlocate %fmm startlocat %fmm absdiffernce %fmm runspeed %fm/s moter_speed %d prm",coordinate_y,lifterp->coord_Y,fabs(lifterp->coord_Y -coordinate_y),runspeed,moter_speed);
    ret1 = synron_position_setvalue(lifterp->motor[0],pulse_value1,moter_speed);//A motor
    if(ret1 !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
    ret2 = synron_position_setvalue(lifterp->motor[1],pulse_value1,moter_speed);//B motor
    if(ret2 !=0)
    {
        LOG_SYNRON("====>synron_position_setvalue motor B error ! ");
        ret3 = synron_position_setvalue(lifterp->motor[0],0,0);
        if(ret3 != 0)
        {
            /*
              Some urgent measures need to be taken here for motorA   
            */
             xp_lifter_error_anction();
            LOG_SYNRON("xp_lifter_stop motorA  fail  and it may be a accident");               
        }
        return -1;
    }
    ifstopflag = 0;
    while(1)
    {   
        ret1 = xp_lifter_get_locate(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
             xp_lifter_error_anction();
            return -1;
        }
          if(ifstopflag == 1)
        {
            break;
        }
       
        //LOG_SYNRON("left_encode:%d encode_A_motor0_Y:%d right_enccode:%d encode_B_motor1:%d",left_encode,lifterp->encode_A_motor0,right_encode,lifterp->encode_B_motor1);
        if(((left_encode == lifterp->encode_A_motor0 )&&(fabs(lifterp->encode_A_motor0 -pulse_value1)>200))||
            ((right_encode == lifterp->encode_B_motor1)&&(fabs(lifterp->encode_B_motor1-pulse_value1)>200)))
        {
            LOG_SYNRON("\r\n ERROR \r cummunication error xp_lifter_get_locate fail and action has happened");
            LOG_SYNRON("left_encode %d right_encode %d  lifterp->encode_A_motor0 %d  lifterp->encode_B_motor1 %d pulse %d",left_encode,
            right_encode,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value1);                                   
            xp_lifter_error_anction();
            return -1;
        }
        if(fabs(lifterp->coord_A_Y-lifterp->coord_B_Y)>4)/*如果左边和右边相差过大*/
        {
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            LOG_SYNRON("\r\n ERROR \r The height difference between the left cylinder and the right cylinder is too great ");
            LOG_SYNRON("\r\n coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d",lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1);
            return -1;
        }
        LOG_SYNRON("\r\n diff_s %f coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d pulse_value1 %d",fabs(lifterp->coord_A_Y-lifterp->coord_B_Y),lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value1);
        /*
        speedl = synron_get_speedvalue(lifterp->motor[0]);
        speedr = synron_get_speedvalue(lifterp->motor[1]);
        LOG_SYNRON("lifterp->motor[0]  %d lifterp->motor[1]  %d",speedl,speedr);
        */
        if((fabs(left_encode-pulse_value1)<40)&&(fabs(right_encode -pulse_value1)<40))
        {
            LOG_SYNRON("The target coordinates reach the specified position");
            ifstopflag = 0;
            break ;
        }
        ret1 = xp_lifter_read_inputsig();
        if(ret1 == -1)
        {
            LOG_SYNRON("xp_lifter_read_inputsig ret1 %d",ret1);
            break;
        }
        left_encode = lifterp->encode_A_motor0;
        right_encode = lifterp->encode_B_motor1;
        aos_msleep(200);
    }
    return 0;
    
}
/**
 * @description: int xp_lifter_accdcctime_set(u16 times)
 * @param {type}  LIFTER_class*lifter
 *                times ms
 * @return: 
 *          0 success
 *          -1 fail
 */
int xp_lifter_accdcctime_set(LIFTER_class*lifterp,u16 times)
{
    int ret = 0;
    if(times <30)
    {
        LOG_SYNRON("warning times is too small value %d",times);
        times = 30;
    }
    LOG_SYNRON("xp_lifter_accdcctime_set  times is %d ",times);
     ret = synron_speedmode_acceleratetime(lifterp->motor[0],times);
    if(ret != 0)
   {
       LOG_SYNRON("lifterp->motor[0] synron_speedmode_acceleratetime fail!!!");           
       return SYNRON_COMMUN_ERR;
   }
    ret = synron_speedmode_deceleratetime(lifterp->motor[0],times);
    if(ret != 0)
   {
       LOG_SYNRON("lifterp->motor[0] synron_speedmode_deceleratetime fail!!!");           
       return SYNRON_COMMUN_ERR;
   }
    ret = synron_speedmode_acceleratetime(lifterp->motor[1],times);
    if(ret != 0)
   {
       LOG_SYNRON("lifterp->motor[1] fail!!! synron_speedmode_acceleratetime");           
       return SYNRON_COMMUN_ERR;
   }
    ret = synron_speedmode_deceleratetime(lifterp->motor[1],times);
    if(ret != 0)
   {
       LOG_SYNRON("lifterp->motor[1] fail!!! synron_speedmode_deceleratetime");           
       return SYNRON_COMMUN_ERR;
   }
    return 0;
}




/**
 * @description: xp_lifter_stop 
 * @param {type}  LIFTER_class*lifter
 * @return: 
 *          0 success
 *          -1 fail
 */

int xp_lifter_stop(LIFTER_class*lifterp)
{

    int ret1 = 0;
    int ret2 = 0;
    ret1= synron_position_setvalue(lifterp->motor[0],0,0);
    if(ret1 != 0)
    {
        LOG_SYNRON("xp_lifter_stop motorA   fail  and it may be a accident");   
        /*
        Some urgent measures need to be taken here for motorA 
        */
        xp_lifter_error_anction();
        return -1 ;
    }
    ret2 = synron_position_setvalue(lifterp->motor[1],0,0);
    if(ret2 != 0)
    {
        LOG_SYNRON("xp_lifter_stop motorB and motorA   fail  and it may be a accident");    
        xp_lifter_error_anction();
        return -1;
    }
    ifstopflag= 1;
    return 0;
}
/**
 * @description: xp_lifter_get_locate 
 * @param {type}  LIFTER_class * lifter
 * @return: 
 *          0 success
 *          -1 fail
 */

int xp_lifter_get_locate(LIFTER_class*lifterp)
{
    
    lifterp->encode_A_motor0 = synron_get_abs_pulsevalue(lifterp->motor[0]);
    lifterp->encode_B_motor1 = synron_get_abs_pulsevalue(lifterp->motor[1]);
    if((lifterp->encode_A_motor0 == READADD_32_ERR)||(lifterp->encode_B_motor1 ==READADD_32_ERR ))
    {
        LOG_SYNRON("the value is error !!!!");
        return -1;
    }
    
    lifterp->coord_A_Y = (double)(lifterp->encode_A_motor0 *COR_PULS_TO_COR_DIS);
    lifterp->coord_B_Y = (double)(lifterp->encode_B_motor1 *COR_PULS_TO_COR_DIS);
    lifterp->coord_Y = (lifterp->coord_A_Y + lifterp->coord_B_Y)/2;
    return 0;
}

/**
 * @description: xp_lifter_get_locate_a
 * @param {type}  LIFTER_class * lifter
 * @return: 
 *          0 success
 *          -1 fail
 */

int xp_lifter_get_locate_a(LIFTER_class*lifterp)
{
    lifterp->encode_A_motor0 = synron_get_abs_pulsevalue(lifterp->motor[0]);
    if(lifterp->encode_A_motor0 == READADD_32_ERR)
    {
        LOG_SYNRON("the value is error !!!!");
        return -1;
    }
    lifterp->coord_A_Y = (double)(lifterp->encode_A_motor0 *COR_PULS_TO_COR_DIS);
    return 0;
}


/**
 * @description: xp_lifter_get_locate_b 
 * @param {type}  LIFTER_class * lifter
 * @return: 
 *          0 success
 *          -1 fail
 */

int xp_lifter_get_locate_b(LIFTER_class*lifterp)
{
    
    lifterp->encode_B_motor1 = synron_get_abs_pulsevalue(lifterp->motor[1]);
    if(lifterp->encode_B_motor1 ==READADD_32_ERR)
    {
        LOG_SYNRON("the value is error !!!!");
        return -1;
    }
    lifterp->coord_B_Y = (double)(lifterp->encode_B_motor1 *COR_PULS_TO_COR_DIS);
    return 0;
}

/**
 * @description: xp_lifter_get_pulse 
 * @param double dis  abosolut locat Y coordinate values unit(mm)
 * @return: 
 *          a pulse value to be reset  scale(0~ +++++)
 *          
 */

int xp_lifter_get_abs_pulse(double coordinate_y)
{
    if(coordinate_y < 0)
    {
        LOG_SYNRON("dis %f and its value <0 error!",coordinate_y);
        return -1;
    }
    s32 coor_pulse_y = 0;//脉冲坐标绝对位置
    coor_pulse_y = (s32)(coordinate_y *COR_DISY_TO_COR_PULS);
    return coor_pulse_y;
}

/**`
 * @description: xp_lifter_check_zero  Correction 0 locate
 * @param double dis  abosolut locat Y coordinate values unit(mm)
 * @return: 
 *        0 success
 *          -1 fail
 */

int xp_lifter_check_zero(void)
{

      int ret = 0;
      for(int i =0;i<2;i++)
      {
          ret = synron_position_re_encode_setvalue(&synro_lifter_handler_A,0);
          if(ret != 0)
          {
              LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_A fail !");
              return -1;
          }
          ret = synron_position_re_locacmd_setvalue(&synro_lifter_handler_A,0);
          if(ret != 0)
          {
              LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_A fail !");
              return -1;
          }
          ret = synron_position_re_encode_setvalue(&synro_lifter_handler_B,0);
          if(ret != 0)
          {
              LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
              return -1;
          }    
          ret = synron_position_re_locacmd_setvalue(&synro_lifter_handler_B,0);
          if(ret != 0)
          {
              LOG_SYNRON("synron_position_re_setvalue synro_lifter_handler_B fail !");
              return -1;
          }
      }
      return 0;

}


/*
* @description: xp_lifter_find_low_limit_position
* @param type:lifter:lifter hander
* @param fun:function
* @return: 
*               0 success
*              -1   fail
* 
* 
*/
int xp_lifter_find_low_limit_position(LIFTER_class*lifterp)
{
    int ret = 0;
    int ret1 = 0;
    int ret3 = 0;
    int pulse_value = -(s32)(COR_DISY_TO_COR_PULS * (SAFE_HEIGHT));
    u16 moter_speed = (u16)(0.02 *COR_UPDOWNSPEED_TO_MPTORPRM);
    ret  = synron_position_setvalue(lifterp->motor[0],pulse_value,moter_speed);//A motor
    if(ret !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
     ret1 = synron_position_setvalue(lifterp->motor[1],pulse_value,moter_speed);//B motor
    if(ret1 !=0)
    {
        LOG_SYNRON("====>synron_position_setvalue motor B error ! ");
        ret3 = synron_position_setvalue(lifterp->motor[0],0,0);
        if(ret3 != 0)
        {
            /*
              Some urgent measures need to be taken here for motorA   
            */
             xp_lifter_error_anction();
            LOG_SYNRON("xp_lifter_stop motorA  fail  and it may be a accident");               
        }
        return -1;
    }
    ifstopflag = 0;
    while(1)
    {
        ret1 = xp_lifter_get_locate(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
             xp_lifter_error_anction();
            return -1;
        }
          if(ifstopflag == 1)
        {
           ifstopflag = 0;
           return 0;
        }
        if(fabs(lifterp->coord_A_Y-lifterp->coord_B_Y)>4)/*如果左边和右边相差过大*/
        {
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            LOG_SYNRON("\r\n ERROR \r The height difference between the left cylinder and the right cylinder is too great ");
            LOG_SYNRON("\r\n coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d",lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1);
            return -1;
        }
        LOG_SYNRON("\r\n diff_s %f coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d pulse_value1 %d",fabs(lifterp->coord_A_Y-lifterp->coord_B_Y),lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value);
        if(xp_io_read_input_pin(1,LOW_LIMIT_POSITION)==0)
        {
            xp_lifter_stop(lifterp);
            LOG_SYNRON("low limit position  have reached ");
            return 0;
        }
        if(-1 == xp_lifter_read_inputsig())
        {
            LOG_SYNRON("driver error or warning ");
            return -1;
        }
        aos_msleep(150);
    }
        return -1;
}


/*
* @description: xp_lifter_find_zero_position
* @param type:void
* @param fun:function
* @return: 
*               0 success
*              -1   fail
* 
* 
*/
int xp_lifter_find_zero_position(LIFTER_class*lifterp)
{
    int ret = 0;
    int ret1 = 0;
    int ret3 = 0;
    static double locat_Y = 0;
    int pulse_value = -(s32)(COR_DISY_TO_COR_PULS * (SAFE_HEIGHT));
    u16 moter_speed = (u16)(0.02 *COR_UPDOWNSPEED_TO_MPTORPRM);
    ret  = synron_position_setvalue(lifterp->motor[0],pulse_value,moter_speed);//A motor
    if(ret !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
     ret1 = synron_position_setvalue(lifterp->motor[1],pulse_value,moter_speed);//B motor
    if(ret1 !=0)
    {
        LOG_SYNRON("====>synron_position_setvalue motor B error ! ");
        ret3 = synron_position_setvalue(lifterp->motor[0],0,0);
        if(ret3 != 0)
        {
            /*
              Some urgent measures need to be taken here for motorA   
            */
             xp_lifter_error_anction();
            LOG_SYNRON("xp_lifter_stop motorA  fail  and it may be a accident");               
        }
        return -1;
    }
    ifstopflag = 0;
    while(1)
    {
        ret1 = xp_lifter_get_locate(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
             xp_lifter_error_anction();
            return -1;
        }
          if(ifstopflag == 1)
        {
             ifstopflag = 0;
             return 0;
        }
        if(fabs(lifterp->coord_A_Y-lifterp->coord_B_Y)>4)/*如果左边和右边相差过大*/
        {
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            LOG_SYNRON("\r\n ERROR \r The height difference between the left cylinder and the right cylinder is too great ");
            LOG_SYNRON("\r\n coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d",lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1);
            return -1;
        }
        LOG_SYNRON("\r\n diff_s %f coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d pulse_value1 %d",fabs(lifterp->coord_A_Y-lifterp->coord_B_Y),lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value);
        if(-1 == xp_lifter_read_inputsig())
        {
            LOG_SYNRON("driver error or warning ");
            return -1;
        }
        if(xp_io_read_input_pin(1,ZERO_LIMIT_POSITION)==0)
        {
            LOG_SYNRON("zero limit position  have reached ");
            xp_lifter_stop(lifterp);
            ret =  xp_lifter_check_zero();
              if(ret != 0)
            {
               LOG_SYNRON("xp_lifter_check_zero error !!!!");
               return -1;
            }
            LOG_SYNRON("zero limit position  have reached ");
            return 0;
            return 0;
        }
        if(xp_io_read_input_pin(1,LOW_LIMIT_POSITION)==0)
        {
            LOG_SYNRON("low limit position  have reached  and then up to find zero point");
            break;
        }
        aos_msleep(150);
    }
    ifstopflag =0;
    ret1 = xp_lifter_get_locate(lifterp);
    if(ret1 != 0)
    { 
        LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
        /*
            临时报警动作
            
        */
         xp_lifter_error_anction();
        return -1;
    }
    locat_Y = lifterp->coord_Y;
    pulse_value = (s32)(COR_DISY_TO_COR_PULS * (SAFE_HEIGHT));
    ret  = synron_position_setvalue(lifterp->motor[0],pulse_value,moter_speed);//A motor
    if(ret !=0)
    {
        LOG_SYNRON("===>synron_position_setvalue motor A error ! ");
        return -1;
    }
     ret1 = synron_position_setvalue(lifterp->motor[1],pulse_value,moter_speed);//B motor
    if(ret1 !=0)
    {
        LOG_SYNRON("====>synron_position_setvalue motor B error ! ");
        ret3 = synron_position_setvalue(lifterp->motor[0],0,0);
        if(ret3 != 0)
        {
            /*
              Some urgent measures need to be taken here for motorA   
            */
             xp_lifter_error_anction();
            LOG_SYNRON("xp_lifter_stop motorA  fail  and it may be a accident");               
        }
        return -1;
    }
    while(1)
    {
        ret1 = xp_lifter_get_locate(lifterp);
        if(ret1 != 0)
        { 
            LOG_SYNRON("xp_lifter_get_locate fail and action has happened");
            /*
                临时报警动作
                
            */
             xp_lifter_error_anction();
            return -1;
        }
          if(ifstopflag == 1)
        {
             ifstopflag = 0;
             return 0;
        }
        if(fabs(lifterp->coord_A_Y-lifterp->coord_B_Y)>4)/*如果左边和右边相差过大*/
        {
            /*
                临时报警动作
                
            */
            xp_lifter_error_anction();
            LOG_SYNRON("\r\n ERROR \r The height difference between the left cylinder and the right cylinder is too great ");
            LOG_SYNRON("\r\n coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d",lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1);
            return -1;
        }
        LOG_SYNRON("\r\n diff_s %f coord_A_Y:%f coord_B_Y:%f encode_A_motor0 %d encode_B_motor1 %d pulse_value1 %d",fabs(lifterp->coord_A_Y-lifterp->coord_B_Y),lifterp->coord_A_Y,lifterp->coord_B_Y,lifterp->encode_A_motor0,lifterp->encode_B_motor1,pulse_value);
        if(xp_io_read_input_pin(1,ZERO_LIMIT_POSITION)==0)
        {
            xp_lifter_stop(lifterp);
            ret =  xp_lifter_check_zero();
              if(ret != 0)
            {
               LOG_SYNRON("xp_lifter_check_zero error !!!!");
               return -1;
            }
            LOG_SYNRON("zero limit position  have reached ");
            return 0;
        }
        if(fabs(lifterp->coord_Y - locat_Y)>1000.00)
        {
            LOG_SYNRON("can not find the zero point");
            return -1;
        }
        if(-1 == xp_lifter_read_inputsig())
        {
            LOG_SYNRON("driver error or warning ");
            return -1;
        }
        aos_msleep(150);
    }
    return -1;
}



/*
* @description: xp_lifter_error_anction
* @param type:void
* @param fun:function
* @param param:void  
* @return: 
*/
void xp_lifter_error_anction(void)
{
    /*
         
    */
    int ret = 999;
    xp_io_output_set(1, L_INPUT_PIN_A,L_HIGH_STATE);
    xp_io_output_set(1, L_INPUT_PIN_B,L_HIGH_STATE);
    aos_msleep(500);
    ret = synron_read_hold(&synro_lifter_handler_A,STATE_DIGITAL_PHYSICAL_INPUT);
    if(ret != 0)
    {
        LOG_SYNRON("synro_lifter_handler_A STATE_DIGITAL_PHYSICAL_INPUT error");
        xp_io_output_set(1, L_EMG_POWEROFF,L_LOW_STATE);    //继电器低电平导通有效
    }
    ret = synron_read_hold(&synro_lifter_handler_A,STATE_DIGITAL_PHYSICAL_INPUT);
    if(ret != 0)
    {
        LOG_SYNRON("synro_lifter_handler_A STATE_DIGITAL_PHYSICAL_INPUT error");
        xp_io_output_set(1, L_EMG_POWEROFF,L_LOW_STATE);    //继电器低电平导通有效
    }
    
}

 /*
 * @description: xp_lifter_read_inputsig
 * @param type:void
 * @param fun:function
 * @param param:void  
 * @return: 
            -1  get error signal
 */
 int xp_lifter_read_inputsig(void)
{
    int ret = 1;
    ret = xp_io_read_input_pin(1,L_OUT_PIN_A);
    if(ret == 0)
    {   
        LOG_SYNRON("xp_io_read_input_pin(1,L_OUT_PIN_A)");
        xp_lifter_error_anction();
        return -1;
    }
    ret = xp_io_read_input_pin(1,L_OUT_PIN_B);
    if(ret == 0)
    {
        LOG_SYNRON("xp_io_read_input_pin(1,L_OUT_PIN_B)");
        xp_lifter_error_anction();
        return -1;
    }
    return ret;
}


/*
* @description: XP_lifter_debug
* @param type:debug type
* @param fun:function
* @param param:type: 
*              fun function 
*              param     
* @return: 
*/

int xp_lifter_debug(char *type,char *fun,char *param)
{
    int ret =0;
    double coory_des =0;
    double run_speed = 0;
    u16 time_ms =0;
    if(type == NULL)
    {
        LOG_SYNRON("type is null error !!");
        return 0;
    }
    if(strcmp(type,"lifter")== 0)
    {
        if(strcmp(fun,"stop") == 0)
        {
            LOG_SYNRON("lifter  have to stop !!!");
            ret = xp_lifter_stop(&lifter);
            if(ret != 0)
            {
                LOG_SYNRON("xp_lifter_stop eror !!!");
            } 
            //xp_lifter_error_anction();
            //xp_io_output_set(1, L_EMG_POWEROFF,L_LOW_STATE);    //继电器低电平导通有效
            return 1;
        }
        else if(strcmp(fun,"init") == 0)
        {
            LOG_SYNRON("lifter  will initialize the hander and configure some parameters!!!");
            ret = xp_lifter_init(1,115200);//debug test port:2 speed 115200
            if(ret != 0)
            {
                LOG_SYNRON("xp_lifter_init fail !!!");
            }
            return 1;
        }
        else if(strcmp(fun,"locate") == 0)
        {
             LOG_SYNRON("get lifter locate!!");
             ret = xp_lifter_get_locate(&lifter);//
             if(ret != 0)
             {
                LOG_SYNRON("xp_lifter_get_locate error !!!!");
             }
             LOG_SYNRON("A %f B %f and avreage %f",lifter.coord_A_Y,lifter.coord_B_Y,lifter.coord_Y);
             LOG_SYNRON("encode_A_motor0 %d encode_B_motor1 %d ",lifter.encode_A_motor0,lifter.encode_B_motor1);
             return 1;
        }
        else if(strcmp(fun,"zero") == 0)
        {
           ret =  xp_lifter_check_zero();
           if(ret != 0)
         {
            LOG_SYNRON("xp_lifter_check_zero error !!!!");
         }
           LOG_SYNRON("xp_lifter_check_zero success");
           return 1;
        }
        else if(strcmp(fun,"accdcc") == 0)
        {
           time_ms = strtoul(param, NULL, 10);
           LOG_SYNRON("accdcc set time_ms is %d ",time_ms);
           ret =  xp_lifter_accdcctime_set(&lifter,time_ms);
           if(ret != 0)
         {
            LOG_SYNRON("xp_lifter_check_zero error !!!!");
         }
           LOG_SYNRON("xp_lifter_accdcctime_set success");
           return 1;
        }
        else if(strcmp(fun,"findl") == 0)   //寻找下限位
        {
            LOG_SYNRON("find the low limit position ");
            ret = xp_lifter_find_low_limit_position(&lifter);
            if(ret != 0)
            {
                LOG_SYNRON("lost the low limit position ");
            }
            LOG_SYNRON("success find the low limit position ");
        }
        else if(strcmp(fun,"findz")== 0)    //寻找零位
        {
            LOG_SYNRON("find the zero limit position ");
            ret = xp_lifter_find_zero_position(&lifter);
            if(ret != 0)
            {
                LOG_SYNRON("lost the zero limit position ");
            }
            LOG_SYNRON("success find the zero limit position ");
            
        }
        else
        {   
            LOG_SYNRON("fun is eror ！！");
            return 0;
        }
    }
    else if(strcmp(type,"lifter_move_t")== 0)
    {
        coory_des = atof(fun);
        time_ms = strtoul(param, NULL, 10);
        LOG_SYNRON("coory_des %f times %d ",coory_des,time_ms);
        ret = xp_lifter_move_t(&lifter,coory_des,time_ms);
        if(ret != 0)
        {
            LOG_SYNRON("debug xp_lifter_move_t(&lifer,coory_des,time_ms) error !!");
        }
        return 1;
    }
    else if(strcmp(type,"lifter_move_s")== 0)
    {
        coory_des = atof((fun));
        run_speed = atof(param);
        LOG_SYNRON("coory_des %f run_speed %f ",coory_des,run_speed);
        ret = xp_lifter_move_s(&lifter,coory_des,run_speed);
        if(ret != 0)
        {
            LOG_SYNRON("debug xp_lifter_move_t(&lifer,coory_des,time_ms) error !!");
        }
        return 1;
    }
    else if(strcmp(type,"lifter_move_sa")== 0)
    {
        coory_des = atof((fun));
        run_speed = atof(param);
        LOG_SYNRON("coory_des %f run_speed %f ",coory_des,run_speed);
        ret = xp_lifter_move_s_a(&lifter,coory_des,run_speed);
        if(ret != 0)
        {
            LOG_SYNRON("debug xp_lifter_move_t(&lifer,coory_des,time_ms) error !!");
        }
        return 1;
    }
    else if(strcmp(type,"lifter_move_sb")== 0)
    {
        coory_des = atof((fun));
        run_speed = atof(param);
        LOG_SYNRON("coory_des %f run_speed %f ",coory_des,run_speed);
        ret = xp_lifter_move_s_b(&lifter,coory_des,run_speed);
        if(ret != 0)
        {
            LOG_SYNRON("debug xp_lifter_move_t(&lifer,coory_des,time_ms) error !!");
        }
        return 1;
    }
    else if(strcmp(type,"lifter_move_abs")== 0)
    {
        coory_des = atof((fun));
        run_speed = atof(param);
        LOG_SYNRON("coory_des %f run_speed %f ",coory_des,run_speed);
        ret = xp_lifter_move_abs(&lifter,coory_des,run_speed);
        if(ret != 0)
        {
            LOG_SYNRON("debug xp_lifter_move_t(&lifer,coory_des,time_ms) error !!");
        }
        return 1;
    }
    else
    {
        return 0;
    }
    return 0;
    
}
